#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=200000;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

class Heap {
public:
  int k[maxn+1], l[maxn+1], r[maxn+1], p[maxn+1], size;

  bool cmp(int a, int b) {
    return k[a]<=k[b];
  }

  void swap(int a, int b) {
    int t;
    t=k[a], k[a]=k[b], k[b]=t;
    t=l[a], l[a]=l[b], l[b]=t;
    t=r[a], r[a]=r[b], r[b]=t;
    t=p[a], p[a]=p[b], p[b]=t;
  }

  void up(int o) {
    if (o>1 && cmp(o, o/2)) {
      swap(o/2, o);
      up(o/2);
    }
  }

  void down(int o) {
    if (((o*2<size && cmp(o*2, o*2+1)) || o*2==size) && cmp(o*2, o)) {
      swap(o*2, o);
      down(o*2);
    } else if ((o*2<size && cmp(o*2+1, o*2)) && cmp(o*2+1, o)) {
      swap(o*2+1, o);
      down(o*2+1);
    }
  }

  void ins(int key, int left, int right, int pos) {
    size++;
    k[size]=key, l[size]=left, r[size]=right, p[size]=pos;
    up(size);
  }

  int pop() {
    int t=k[1];
    swap(size, 1);
    size--;
    down(1);
    return t;
  }
};

class SegmentTree {
public:
  int v[4*maxn+1];

  void init(int o, int l, int r) {
    v[o] = maxn+1;
    if (l!=r) {
      int mid=(l+r)/2;
      init(o*2, l, mid);
      init(o*2+1, mid+1, r);
    }
  }

  void set(int o, int l, int r, int t, int tv) {
    if (l==r) {
      v[o] = tv;
    } else {
      int mid=(l+r)/2;
      if (t<=mid) {
	set(o*2, l, mid, t, tv);
      } else {
	set(o*2+1, mid+1, r, t, tv);
      }
      v[o] = min(v[o*2], v[o*2+1]);
    }
  }

  int getMin(int o, int l, int r, int tl, int tr) {
    if (l==tl && r==tr) {
      return v[o];
    } else {
      int mid=(l+r)/2, ret=maxn+1;
      if (tl<=mid) {
	ret = min(ret, getMin(o*2, l, mid, max(l, tl), min(mid, tr)));
      }
      if (tr>mid) {
	ret = min(ret, getMin(o*2+1, mid+1, r, max(mid+1, tl), min(r, tr)));
      }
      return ret;
    }
  }
};

void insMin(Heap &h, SegmentTree minp[2], int l, int r, int map[], int n) {
  int temp=minp[l%2].getMin(1, 1, n, l, r);
  h.ins(temp, l, r, map[temp]);
}

int main() {
  freopen("seq.in", "r", stdin);
  freopen("seq.out", "w", stdout);

  static int p[maxn+1], map[maxn+1];
  int n;
  scanf("%d", &n);

  static SegmentTree minp[2];
  minp[0].init(1, 1, n), minp[1].init(1, 1, n);
  for (int i=1; i<=n; i++) {
    scanf("%d", p+i);
    map[p[i]] = i;
    minp[i%2].set(1, 1, n, i, p[i]);
  }

  static Heap que;
  static int q[maxn+1];
  insMin(que, minp, 1, n, map, n);
  for (int i=1; i<n; i+=2) {
    int l=que.l[1], r=que.r[1], o=que.p[1], x=map[minp[!(o%2)].getMin(1, 1, n, o+1, r)];
    que.pop();
    q[i] = p[o], q[i+1] = p[x];
    if (o>l) {
      insMin(que, minp, l, o-1, map, n);
    }
    if (x-o>1) {
      insMin(que, minp, o+1, x-1, map, n);
    }
    if (x<r) {
      insMin(que, minp, x+1, r, map, n);
    }
  }

  for (int i=1; i<=n; i++) {
    printf("%d ", q[i]);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
